var _as = {

    scrollbar:function(){
        // $(".scrollbar").mCustomScrollbar({
        //     scrollButtons:{
        //         enable:true
        //     }
        // });
    },
    btnOk:function(callback, obj) {
        // startDrag(document.getElementById('jacBar'),document.getElementById('jacBox'));
        $("#jOk").click(function() {
            $("#jac").remove();
            if (typeof(callback) == 'function') {
                callback(obj);
            }
        });
    },
    btnNo:function() {
        $("#jNo,#jacClose").click(function() {
            $("#jac").remove();
            $("div.wrap").find("#loading").hide();
        });
    },
    jMaxLength:function(data) {
        // var p = data.split("</p>"),l=0;
        // for(var i in p) {
        //     var ll = p[i].length;
        //     if(ll>l) {
        //         l=ll;
        //     }
        // }
        // l = l*1.2;
        $("#jac .modal-dialog").css({"display": "block", "max-width": "600px", "min-width": "200px;", "max-height": "600px", "min-height": "200px;"});// 动态设置弹出层宽度
        var rw = parseInt($("#jac #jacBox").css("width"));
        var rh = parseInt($("#jac #jacBox").css("height"));
        $("#jac #jacBox").css({"left": "50%", "margin-left": "-" + rw/2 + "px", "top": "50%", "margin-top": "-" + rh/2 + "px"});// 动态设置弹出层居中显示
        $("#jac #jacMessage").css({"display": "block", "max-height": "500px", "overflow-y": "auto"});// 动态设置弹出层居中显示
        startDrag(document.getElementById('jacBar'),document.getElementById('jacBox'));
    },
    jAlert:function(data, callback, obj) {
        $.get('./scripts/plugins/jac.tmpl', function(tmpl) {
            $("#jac").remove();
            $('body').append(tmpl);
            $("#jNo").hide();
            _as.btnOk(callback, obj);
            _as.btnNo();
            data = data.indexOf('<p>') > -1 ? data : "<p>" + data + "</p>";
            $("#jac").find("#jacMessage").append(data);
            _as.jMaxLength(data);
        })
    },
    jConfirm:function(data, callback, obj) {
        $.get('./scripts/plugins/jac.tmpl', function(tmpl) {
            $("#jac").remove();
            $('body').append($.tmpl(tmpl, data));
            _as.btnOk(callback, obj);
            _as.btnNo();
            data = data.indexOf('<p>') > -1 ? data : "<p>" + data + "</p>";
            $("#jac").find("#jacMessage").append(data);
            _as.jMaxLength(data);
        })
    },
    shake:function(e, oncomplete, distance, time, onoff) {
        var ee=e;
        if(typeof e === "string") e = document.getElementById(e);
        if(!distance) distance = 5;
        if(!time) time = 500;
        var originalStyle = e.style.cssText;
        e.style.position = "relative";
        var start = (new Date()).getTime();
        if(onoff=="noShowRed") {
            $("#"+ee).css("background-color","#f10000").focus();
            // e.style.backgroundColor = "#f10000";
        } else {
            $("table").find("div").css("background-color","#f10000");
        }
        animate();
        function animate() {
            var now = (new Date()).getTime();
            var elapsed = now - start;
            var fraction = elapsed/time;
            if(fraction < 1) {
                var x = distance * Math.sin(fraction*4*Math.PI);
                e.style.left = x + "px";
                setTimeout(animate, Math.min(25, time-elapsed));
            } else {
                e.style.cssText = originalStyle;
                if(oncomplete) oncomplete(e);
            }
        }
    },
    fadeOut:function(e, oncomplete, time) {
        if(typeof e === "string") e = document.getElementById(e);
        if(!time) time = 500;
        var ease = Math.sqrt;
        var originalStyle = e.style.cssText;

        var start = (new Date()).getTime();
        animate();
        function animate() {
            var elapsed = (new Date()).getTime()-start;
            var fraction = elapsed/time;
            if(fraction < 1) {
                var opacity = 1 - ease(fraction);
                e.style.opacity = String(opacity);
                setTimeout(animate, Math.min(25, time-elapsed));
            } else {
                // e.style.opacity = "0";
                e.style.cssText = originalStyle;
                $("table").find("div").css("background-color","");
                if(oncomplete) oncomplete(e);
            }
        }
    },
    maxL:function(dom,maxL) {
        $("table").one("webkitAnimationEnd", "tr", function(){
            $("table").find("tr").removeClass('slideInRight');
        })
        $('[data-toggle="tooltip"]').tooltip();
        $(dom).find("span.maxL").each(function(index, el) {
            var $this = $(this),
                text = $this.attr("data-original-title");
            if(text.length > maxL) {
                text = text.substr(0,maxL);
                $this.text(text+"...").css("cursor","help");
            } else {
                $this.parents("td").empty().text(text);
            }
        });
    },
    maxLe:function(dom,maxL) {
        $("table").one("webkitAnimationEnd", "tr", function(){
            $("table").find("tr").removeClass('slideInRight');
        })
        $('[data-toggle="tooltip"]').tooltip();
        $(dom).find("span.maxL").each(function(index, el) {
            var $this = $(this),
                text = $this.attr("data-original-title");
            if(text.length > maxL) {
                text = text.substr(0,maxL);
                $this.text(text+"...").css("cursor","help");
            } else {
                $this.empty().text(text);
            }
        });
    },
    maxLee:function(dom,maxL) {
        $("table").one("webkitAnimationEnd", "tr", function(){
            $("table").find("tr").removeClass('slideInRight');
        })
        $('[data-toggle="tooltip"]').tooltip();
        $(dom).find("span.maxL").each(function(index, el) {
            var $this = $(this),
                text = $this.attr("title");
                $this.attr("data-original-title", text);
            if(text.length > maxL) {
                text = text.substr(0,maxL);
                $this.text(text+"...");
            } else {
                $this.empty().text(text);
            }
        });
    },
    clickOften:function() {
        if(parseInt(sessionStorage.clickOften)) {
            sessionStorage.clickOften=0;
            setTimeout(function() {
                sessionStorage.clickOften=1;
            }, 1500);
            return false;
        }else {
            // _as.jAlert("<p>非法操作：频繁请求！</p>");
            return true;
        }
    },
    getRequest: function getRequest() {
      var url = location.search; //获取url中"?"符后的字串
      var theRequest = new Object();
      if (url.indexOf("?") !== -1) {
        var str = url.substr(1);
        var strs = str.split("&");
        for (var i = 0; i < strs.length; i++) {
          theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
        }
      }
      return theRequest;
    }

}

